<?php
    require_once('../includes/DbConnector.php');
    
    if(isset($_POST['action']) && !empty($_POST['action'])) {
        // INPUT DATA.
        $action = $_POST['action'];
        $barid = $_POST['barid'];
        $connector  = new DbConnector();
        $sql = "select
                b.*,
                ifnull((select bi.image from bar_image bi where b.image_id = bi.image_id), null) image,
                ifnull((select bi.image_type from bar_image bi where b.image_id = bi.image_id), 'image/png') image_type,
                p.name place,
                c.name country,
                bs.name status,
                ua.first_name owner_first_name,
                ua.last_name owner_last_name
                from bar b, bar_status bs, user_account ua, place p, country c
                where b.postal_no = p.postal_no
                and p.country_code = c.country_code
                and b.status_id = bs.status_id
                and b.user_id = ua.user_id
                and b.bar_id = '$barid'";
        $result = $connector->query($sql);
        
        $a = mysql_fetch_assoc($result);
        
        $a['image'] = base64_encode($a['image']);
        
        echo json_encode($a);
    }
?>